package com.chinatechstar.component.commons.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MultipartException;

import javax.servlet.http.HttpServletResponse;

/**
 * @author Rei
 */
public class FileException {

    /**
     * 处理文件上传大小超限制
     *
     * @param exception 文件异常
     * @return exception
     */
    @ExceptionHandler(value = MultipartException.class)
    public String fileUploadExceptionHandler(MultipartException exception, HttpServletResponse response) {
        String msg;
        if (exception.getRootCause() != null) {
            int maxFileSize = 1024;
            msg = "上传文件过大[单个文件大小不得超过" + maxFileSize + "MB]";
        } else {
            exception.getRootCause();
            msg = "文件上传失败[服务器异常]";
        }

        return msg;
    }
}
